<style>
.layui-table-cell {
		padding:0 5px;
		height:auto;
		overflow:visible;
		text-overflow:inherit;
		white-space:normal;	           
		word-break: break-all;
	}

.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
</style>
<div class="fixed-bar">
<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search-optable">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">订单号</label>
			<div class="layui-input-inline">
				<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
			</div>
		</div>
		{if env('env_site') == 'riwei' }
		<div class="layui-inline">
			<label class="layui-form-label">客户单号</label>
			<div class="layui-input-inline">
				<input type="text" name="ext_id" lay-verify="" placeholder="输入客户单号" class="layui-input">
			</div>
		</div>
		{/if}
		<div class="layui-inline">
			<label class="layui-form-label">SKU</label>
			<div class="layui-input-inline">
				<input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">所属工厂</label>
			<div class="layui-input-inline">
				{:Form::select('factory_id', '', $factoryKV, '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">订单状态</label>
			<div class="layui-input-inline">
				{:Form::select('order_status', '', ['' => '请选择', 1=>'未采购', 2=>'已采购', 3=>'已裁床', 4=>'已车缝', 5=>'已后整', 6=>'已完成', 99=>'已废弃'], '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">下单日期</label>
			<div class="layui-input-inline">
				<input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择下单日期" class="layui-input">
			</div>
		</div>
        <div class="layui-inline">
			<label class="layui-form-label">入单时间</label>
			<div class="layui-input-inline">
				<input type="text" name="caigou_cost_over_time" readonly="" id="caigou_cost_over_time" lay-verify="" placeholder="选择入单时间" class="layui-input">
			</div>
		</div>
        <div class="layui-inline removeStat">
            <label class="layui-form-label">是否催单</label>
              <div class="layui-input-inline">
                  {:Form::select('urge_order', 2, [2 => '请选择', 0=>'不催单', 1=>'催单'], '', '')}
              </div>
        </div>
        <div class="layui-inline removeStat">
            <label class="layui-form-label">是否共用</label>
              <div class="layui-input-inline">
                  {:Form::select('is_share', 2, [2 => '请选择', 0=>'不共用', 1=>'共用'], '', '')}
              </div>
        </div>
		<div class="layui-inline">
			<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
            <button type="button" class="layui-btn layui-btn-primary hisi-export">导出</button>
		</div>
	</div>
</form>
</div>

<table id="dataTable" lay-filter='dataTable'></table>

{include file="system@block/layui" /}

<script type="text/html" id="picTpl">
    <span class="lay-pic-container" src="{{ d.sInfo.pic }}">
		<img src="{{ d.sInfo.ori_pic }}" class="lay-pic">
		{{# if(d.status==99){ }}
			<span class="sign"><img src="/static/system/image/sign_delete.png"></span>
		{{# }else if(d.status==2){ }}
			<span class="sign"><img src="/static/system/image/sign_over.png"></span>
		{{# }else if(d.tail_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_tail.png"></span>
		{{# }else if(d.chejian_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_workshop.png"></span>
		{{# }else if(d.caichuang_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_cutting.png"></span>
		{{# }else if(d.caigou_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_purchasing_done.png"></span>
		{{# }else { }}
			<span class="sign"><img src="/static/system/image/sign_purchasing_todo.png"></span>
		{{# } }}
	</span>
</script>
<script type="text/html" id="skuTpl">
    {{# if(d.urgeOrder== 1){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs layui-bg-red">催单</a>
    {{# } }}
    <span class="copy-item">{{ d.client_ordernum }}</span> <br>
    <span class="copy-item">{{ d.sku }}</span></br>
    {{ orderFrom[d.is_auto_import] }}<br>
	{{# if(d.status == 99){ }}<span class="layui-badge">{{ d.delete_text }}</span><br> {{# } }}
</script>
<script type="text/html" id="createTimeTpl">
    {{ layui.util.toDateString(d.create_time * 1000) }} <br>
    {{ d.quantity }} 件
</script>
<script type="text/html" id="factoryTpl">
    {{ d.factory_name }} <br>
    {{ d.o_type_text }}
</script>
<script type="text/html" id="orderNumTpl">
	{{# for(var i in d.osList){ }}
    	{{ d.osList[i].size_name }}： {{ d.osList[i].order_count }} / {{ d.osList[i].shicai_count }} / {{ d.osList[i].jiaohuo_count }} / {{ d.osList[i].daohuo_count }} <br>
	{{# } }}
	总数：{{ d.osStat.order_count }} / {{ d.osStat.shicai_count }} / {{ d.osStat.jiaohuo_count }} / {{ d.osStat.daohuo_count }}
</script>

<script type="text/html" id="feedTpl">
    <div class="feed-btn-{{d.mid}}">
<!--        <a href="javascript:void(0)" class="layui-btn layui-btn-primary layui-btn-xs feed-btn" data-mid="{{ d.mid }}" lay-event="feed-btn"></a>-->
        <span><a href="{:url('stallFeedDetail')}?mid={{ d.mid }}" title="补退明细" class="hisi-iframe feed-detail-{{ d.mid }}" hisi-data="{width: '1200px', height: '90%'}">
        补料{{ d.billing_caigou_count_feed }}</a></span>
    </div>
</script>
<script type="text/html" id="billingCaigouCountTpl">
    <span class="billingCaigouCount-{{ d.mid }}">{{d.billing_caigou_count}}</span>
</script>
<script type="text/html" id="billingCaigouCountOriTpl">
    <span class="billingCaigouCountOri-{{ d.mid }}">{{d.billing_caigou_count_ori}}</span>
</script>

<script type="text/html" id="caigouIsEnoughTpl">
  <input type="checkbox" name="caigou_is_enough" title="足米" value="{{d.mid}}" lay-filter="caigou-is-enough" {{ d.caigou_is_enough == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="caigouIsSignTpl">
  <input type="checkbox" name="caigou_is_sign" title="签单" value="{{d.mid}}" lay-filter="caigou-is-sign" {{ d.caigou_is_sign == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="subbtnTpl">
    <div class="subbtn-big-{{ d.mid }}">
    {{# if(d.caigou_cost_status == 1){ }}
        <a class="layui-btn layui-btn-xs subbtn-{{ d.mid }}" lay-event="save-check">更正</a></br>
        <a class="subbtn-{{ d.mid }}">已审核</a>
    {{# }else if(d.caigou_cost_status == 2){ }}
    <a class="layui-btn layui-btn-xs subbtn-{{ d.mid }}" lay-event="save">修改</a></br>
        <a class="layui-btn layui-btn-xs subbtn-{{ d.mid }}" lay-event="check">审核</a>
    {{# }else{ }}
        <a class="layui-btn layui-btn-xs subbtn-{{ d.mid }}" lay-event="save">确认</a>
    {{# } }}
    </div>
</script>
<script type="text/html" id="priceTpl">
    {{# if(parseFloat(d.caigou_unitprice) > parseFloat(d.customer_price)){ }}  
        <span style="color:red">{{d.caigou_unitprice}}</span>
    {{# }else{ }}
        {{d.caigou_unitprice}}
    {{# } }}    
</script>
<script type="text/html" id="nameTpl">
    {{# if(d.caigou_cost_status == 0 && d.is_make_tag==1 && d.mInfo.type !="accessories"){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs layui-bg-red">催单</a>
    {{# } }}
    {{# if(d.is_share== 1){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs layui-bg-orange">共</a>
    {{# } }}
    {{layui.tool.formatMaterialType(d.mInfo.type,'',2)}}<span class='copy-item'>{{d.mInfo.name}}</span>
</script>

<script type="text/html" id="stallOrderTimeTpl">
<input type="text" name="stall_order_time" readonly="" id="stall_order_time{{d.mid}}" value="{{layui.util.toDateString(d.stall_order_time * 1000)}}" lay-verify="" class="layui-input stall_order_time" lay-event="stall_order_time" style="border: none">
</script>
<script type="text/html" id="caigouSubtotalMoney">
    
    <span class="caigouSubtotal-{{ d.mid }}">{{d.caigou_subtotal_money}}</span>
</script>
<script type="text/html" id="stallIdTpl">
{{# if(d.stall_id!=0) { }}
    <div class="stall-select">
        {:Form::select('stall_id','', $stallsKV, 'stall-ids-{literal}{{d.mid}}{/literal}', 'layui-input','lay-search="" lay-verify="required"')}
    </div>
{{# } }} 
</script>
<script type="text/javascript">
    var orderFrom = {:json_encode($orderFrom[]=[0 => ''] + config('mimo.order_from'));};  
	layui.use([ 'opTable', 'jquery', 'tool', 'laydate','form'], function() {
		var $ = layui.jquery;
		var laydate = layui.laydate,form=layui.form;
        
		laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});
        
		laydate.render({
		    elem: '#caigou_cost_over_time'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#caigou_cost_over_time').val(value);
            	$('#layui-laydate2').remove();//关闭面板
            }
		});

        var opTable = layui.opTable.render({
                elem : '#dataTable'
                ,url : '{:url()}'
                ,page: true
                ,limit: 20
                ,limits: [20,50,100,150,200]
                ,text: {
                    none : '暂无相关数据'
                }
                ,toolbar: '#toolbar'
                ,defaultToolbar: ['filter', 'exports', 'print']
                ,cols : [[ 
                    {field:'pic',title : '图片', templet:'#picTpl',width:110}
                    ,{field:'client_ordernum',title : '订单号/SKU', templet:'#skuTpl',width:200}
                    ,{field:'create_time',title : '下单日期/订单数', templet:'#createTimeTpl'}
                    ,{field:'factory_id',title : '工厂/订单类型', templet:'#factoryTpl'}
                    ,{field:'daohuo_count',title : '下单数/裁床数/车间数/出货数', templet:'#orderNumTpl',width:210}
                    ,{field:'caigou_total_money',title : '合计金额', templet:function(d){return '<span class="caigou-total-money-'+d.id+'">'+d.caigou_total_money+'</span>'}}
                    ,{field:'caigou_cost_remark',title : '采购成本备注',edit:'text',style:'border-bottom:2px dotted #5FB878;'}
                    ,{field:'caigou_pricing',title : '核价情况',edit:'text',style:'border-bottom:2px dotted #5FB878;'}
                ]]
                ,onEdit: function(obj) {
                    var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段

                    // 编辑采购成本备注
                    if (field == 'caigou_cost_remark') {
                        $.ajax({
                           type: "POST",
                           url: "{:url('costRemark')}",
                           data: "order_id="+data.id+"&remark="+value,
                           dataType:"json",
                           success: function(res){
                              if (res.code == 1) {
                                 layer.msg(res.msg, {icon: 1});
                              } else {
                                 layer.msg(res.msg, {icon: 2,anim: 6});
                              }
                           }
                        });
                    } else if(field == 'caigou_pricing') {	// 核价情况
                        $.ajax({
                               type: "POST",
                               url: "{:url('caigouPricing', ['_t' => 1])}",
                               data: "order_id="+data.id+"&remark="+value,
                               dataType:"json",
                               success: function(res){
                                  if (res.code == 1) {
                                     layer.msg(res.msg, {icon: 1});
                                  } else {
                                     layer.msg(res.msg, {icon: 2,anim: 6});
                                  }
                               }
                        });
                    }
                }
                //  展开的列配置
                ,openTable: function (itemData) {
                    return {
                        elem: '#child' + itemData.LAY_INDEX
                        ,id: 'child' + itemData.LAY_INDEX
                        ,data: layui.tool.setDataToList(itemData, itemData.omList)
                        ,limit: 20
                        ,cellMinWidth: 100
                        ,toolbar: true
                        ,defaultToolbar: ['filter', 'exports', 'print']
                        ,cols: [[
                            {field: 'name', title: '材料名称',templet:'#nameTpl',width:70}
                            ,{field:'supplier',title : '指定供应商',templet:function(d){return "<a href='javascript:void(0);' class='supplier' data-supplier='"+d.mInfo.supplier+"' data-address='"+d.mInfo.address+"' data-contact='"+d.mInfo.contact+"'>"+d.mInfo.supplier+"</a>";},width:60}
                            ,{field:'stalls_id',title : '供应商',templet:'#stallIdTpl',width:100}
                            ,{field:'model', title:'型号',templet:function(d){return d.mInfo.model;},width:60}
                            ,{field:'colornum', title:'色号',templet:function(d){return d.mInfo.colornum;},width:55}
                            ,{field:'color', title:'颜色',templet:function(d){return d.mInfo.color;},width:55}
                            ,{field:'col1',title : '客户幅宽/克重/米',width:85,templet:function(d){return d.fabric_width+" / "+d.weight+" / "+layui.tool.bcdiv(layui.tool.bcdiv(100000, d.fabric_width), d.weight);}}
                            ,{field:'stall_order_time',title : '供应商单日期',templet: '#stallOrderTimeTpl',width:110}
                            //,{field:'stall_order',title : '供应商单号',edit:'text',style:'border-bottom:2px dotted #5FB878;',width:70}
                            ,{field:'material_dosage', title:'采购量',templet:function(d){return layui.tool.bcmul(d.material_dosage, d.p.quantity);},width:60}
                            ,{field:'billing_caigou_kgcount',title : '开单采购公斤数',edit:'text',style:'border-bottom:2px dotted #5FB878;',width:70}
                            ,{field:'billing_caigou_kgprice',title : '开单采购公斤价',edit:'text',style:'border-bottom:2px dotted #5FB878;',width:70}
                            ,{field:'caigou_unitprice',title : '单价',edit:'text',style:'border-bottom:2px dotted #5FB878;', templet: '#priceTpl',width:60 }	//
                           // ,{field:'customer_price',title : '客户单价',templet:function(d){return d.customer_price;},width:60}	
                            ,{field:'billing_caigou_count',title : '开单采购总数(米)',templet: '#billingCaigouCountTpl',width:60}
                            ,{field:'billing_caigou_count_ori',title : '原始开单采购量(米)',edit:'text',style:'border-bottom:2px dotted #5FB878;',templet: '#billingCaigouCountOriTpl',width:60}
                            ,{field:'billing_caigou_count_feed',title : '开单采购补量', templet: '#feedTpl',width:60}
                            ,{field:'tiaoshu',title : '采购条数',width:60}
                            ,{field:'weight_shrink', title:'缩水前重量',width:60}
                            ,{field:'weight_page', title:'纸筒重量',width:60}
                            ,{field:'checkcloth_length', title:'验布米长',width:60}
                            ,{field:'shrink_length', title:'缩水米长',width:60}

                            ,{field:'caigou_subtotal_money', title:'金额',templet:'#caigouSubtotalMoney',width:60}
                            //,{field:'caigou_is_enough', title:'足米', templet: '#caigouIsEnoughTpl',unresize: true,width:90}
                            ,{field:'caigou_is_sign', title:'签单', templet: '#caigouIsSignTpl',unresize: true,width:90}
                            // ,{field:'tiaoshu_detail', title:'多少条/每条数量/总量'}
                            // ,{field:'yuque_count', title:'余缺量'}
                            // ,{field:'true_fabric_width', title:'实际幅宽',edit:'text',style:'border-bottom:2px dotted #5FB878;'}
                            // ,{field:'true_weight', title:'实际克重',edit:'text',style:'border-bottom:2px dotted #5FB878;'}
                            ,{field:'subbtn', title:'确认', templet:'#subbtnTpl',width:80}
                        ]]
                        ,done: function (res) {
                            // 监听子表单元格修改
                            layui.table.on('edit(' + 'child' + itemData.LAY_INDEX + ')', function (obj) {
                                var d = obj.data,field=obj.field;
                                if(!checkData(d)) return;
                                var fabricWidth = d.fabric_width;//幅宽
                                var weight = d.weight;//克重
                                var mid = d.mid;
                                var caigouUnitprice = d.caigou_unitprice;
                                var billingCaigouCountOri = d.billing_caigou_count_ori;
                                	
                                if(field=="billing_caigou_kgprice") { // 录入 开单采购公斤价，重新计算 单价
                                	var billingCaigouKgprice = d.billing_caigou_kgprice;//开单采购公斤价
                                    caigouUnitprice = layui.tool.bcmul(fabricWidth * weight , billingCaigouKgprice/100000);//单价=幅宽 * 克重 * 开单采购公斤价/100000
                                    obj.update({caigou_unitprice:caigouUnitprice});
                                }
                                if (field=="billing_caigou_kgcount") { // 录入 开单采购公斤数，重新计算 开单采购总数
                                    var billingCaigouKgcount = d.billing_caigou_kgcount;//开单采购公斤数
                                    var billingCaigouCountOri = layui.tool.bcdiv((billingCaigouKgcount*100000), fabricWidth*weight);//原始开单采购总数=(开单采购公斤数*100000)/幅宽 / 克重
                                }
                                
                                // 异步计算小计金额
                                $.ajax({
                                    type: "POST",
                                    url: "{:url('getCaigouSubtotalMoney')}",
                                    data: "mid="+mid+"&caigou_unitprice="+caigouUnitprice+"&billing_caigou_count_ori="+billingCaigouCountOri,
                                    dataType:"json",
                                    success: function(res){
                                       if (res.code == 1) {
                                           obj.update({caigou_subtotal_money:res.data.caigouSubtotalMoney,
                                        	   billing_caigou_count:res.data.billingCaigouCount,
                                        	   billing_caigou_count_ori:billingCaigouCountOri});
                                       } else {
                                    	   layer.msg(res.msg, {icon: 2,anim: 6,end:function(){reloadTable()}});
                                       }
                                    }
                                 });
                                
                            });
                            var data=res.data;
                            for (var i in data){
                                var value=layui.util.toDateString(data[i]['stall_order_time'] * 1000, 'yyyy-MM-dd');
								var nowtime=new Date();
                                if(data[i]['stall_order_time']==0) value=nowtime.getFullYear()+"-"+(nowtime.getMonth()+1)+"-01";
                                laydate.render({
                                    elem: "#stall_order_time"+data[i]['mid'], //指定元素
                                    value: value 
                                });
                                $('#stall-ids-'+data[i]['mid']).val(data[i]['stall_id']);
                                layui.form.render("select");
                            }
                            // 监听子表修改按钮点击
                            layui.table.on('tool(' + 'child' + itemData.LAY_INDEX + ')', function(obj){
                                var d = obj.data;
                                var layEvent = obj.event;
                                var mid = d.mid;
                                var elem="#stall_order_time"+mid;                           
                                if (layEvent == 'stall_order_time') {
                                }
                                // 点击补料
                                if (layEvent == 'feed-btn') {
                                    var layerFeed = layer.prompt({title: '请输入数量', formType: 0,success:function(){
                                        // 键盘事件，判断回车
                                        $("input.layui-layer-input").on('keydown',function(e){
                                            if (e.which == 13) {
                                                feedEvent($(this).val(), mid, obj);
                                            }
                                        });
                                    }}, 
                                    function(number){
                                        feedEvent(number, mid, obj);
                                    });
                                    return ;
                                }

                                if(!checkData(d)) return;			            	

                                var mid = d.mid;
                                var stallName = d.stall_id;
                                var stallId = $('#stall-ids-'+mid).val();
                                var otherParam = '';
                                if (caigouIsEnough.hasOwnProperty(mid)) {
                                    otherParam += "&caigou_is_enough="+caigouIsEnough[mid];
                                }
                                if (caigouIsSign.hasOwnProperty(mid)) {
                                    otherParam += "&caigou_is_sign="+caigouIsSign[mid];
                                }
                                var caigouUnitprice = d.caigou_unitprice;
                                var billingCaigouCount = d.billing_caigou_count;
                                var billingCaigouCountOri = d.billing_caigou_count_ori;
                                var caigouSubtotalMoney = d.caigou_subtotal_money;
                                var trueFabricWidth = d.true_fabric_width;
                                var trueWeight = d.true_weight;
                                var billingCaigouKgcount = d.billing_caigou_kgcount;
                                var billingCaigouKgprice = d.billing_caigou_kgprice;
                                var stallOrderTime=$("#stall_order_time"+mid).val();
                                var stallOrder=d.stall_order;
                                // 点击确认/修改
                                if (layEvent == 'save') {
                                    $.ajax({
                                       type: "POST",
                                       url: "{:url('costConfirm')}",
                                       data: "mid="+mid+"&caigou_unitprice="+caigouUnitprice+"&billing_caigou_count="+billingCaigouCount+"&billing_caigou_count_ori="+billingCaigouCountOri+"&caigou_subtotal_money="+caigouSubtotalMoney+"&true_fabric_width="+trueFabricWidth+"&true_weight="+trueWeight+otherParam+"&billing_caigou_kgcount="+billingCaigouKgcount+"&billing_caigou_kgprice="+billingCaigouKgprice+"&stall_order_time="+stallOrderTime+"&stall_order="+stallOrder+"&stall_id="+stallId,
                                       dataType:"json",
                                       success: function(res){
                                          if (res.code == 1) {  
                                                if(res.data['exception']==1){
                                                    layer.confirm(res.data['msg'], {
                                                        btn: ['知道了']
                                                    },function(){
                                                        layer.msg(res.msg, {icon: 1});
                                                    });
                                                } else{
                                                    layer.msg(res.msg, {icon: 1});
                                                }
                                                $('.subbtn-'+mid).addClass('layui-btn-normal');
                                                $('.subbtn-big-'+mid).html('<a class="layui-btn layui-btn-xs subbtn-'+mid+'" lay-event="save">修改</a></br><a class="layui-btn layui-btn-xs subbtn-'+mid+'" lay-event="check">审核</a>');
                                                
                                                 
                                          } else {
                                             layer.msg(res.msg, {icon: 2,anim: 6});
                                          }
                                       }
                                    });
                                }else if(layEvent == 'check'){                            
                                    if (stallName=="" || stallId==0) {
                                        layer.msg('供应商不能为空', {icon: 2,anim: 6});
                                        return false;
                                    }          
                                    $.ajax({
                                       type: "POST",
                                       url: "{:url('costCheck')}",
                                       data: "mid="+mid+"&stall_id="+stallId,
                                       dataType:"json",
                                       success: function(res){
                                          if (res.code == 1) {
                                            $('.subbtn-'+mid).addClass('layui-btn-normal');
                                            $('.subbtn-big-'+mid).html('<a class="layui-btn layui-btn-xs subbtn-'+ d.mid +'" lay-event="save-check">更正</a></br><a class="subbtn-'+mid+'">已审核</a>');
                                             layer.msg(res.msg, {icon: 1});
                                          } else {
                                             layer.msg(res.msg, {icon: 2,anim: 6});
                                          }
                                       }
                                    });
                                }else if(layEvent=='save-check'){
                                    $.ajax({
                                       type: "POST",
                                       url: "{:url('costConfirm1')}",
                                       data: "mid="+mid+"&caigou_unitprice="+caigouUnitprice+"&billing_caigou_count="+billingCaigouCount+"&billing_caigou_count_ori="+billingCaigouCountOri+"&caigou_subtotal_money="+caigouSubtotalMoney+"&true_fabric_width="+trueFabricWidth+"&true_weight="+trueWeight+otherParam+"&billing_caigou_kgcount="+billingCaigouKgcount+"&billing_caigou_kgprice="+billingCaigouKgprice+"&stall_order_time="+stallOrderTime+"&stall_order="+stallOrder+"&stall_id="+stallId,
                                       dataType:"json",
                                       success: function(res){
                                          if (res.code == 1) {
                                              if(res.data['exception']==1){
                                                    layer.confirm(res.data['msg'], {
                                                        btn: ['知道了']
                                                    },function(){
                                                        layer.msg(res.msg, {icon: 1});
                                                    });
                                                } else{
                                                    layer.msg(res.msg, {icon: 1});
                                                }
                                          } else {
                                             layer.msg(res.msg, {icon: 2,anim: 6});
                                          }
                                       }
                                    });
                                }
                            });
                        }
                    }
                  }
                ,openType : 1
                ,done: function(res, curr, count){
                    opTable.openAll();
                    $('.stall-select .layui-anim-upbit').append("<a href='{:url('Stalls/add')}' hisi-data='{}' style='margin-left:5px' class='layui-btn hisi-iframe'>去新增</a>");

                }
            });
	
       
		// 供应商点击
		$(document).on('click','.supplier',function(){
			var content = $(this).attr('data-supplier') +"<br>"+ $(this).attr('data-contact') +"<br>"+ $(this).attr('data-address')
			layer.tips(content, this);
		});
		
		var caigouIsEnough = [];
		layui.form.on('checkbox(caigou-is-enough)', function(obj){
			var mid = this.value;
			var v = obj.elem.checked == true ? 1 : 0;
			caigouIsEnough[mid] = v;
		});
		var caigouIsSign = [];
		layui.form.on('checkbox(caigou-is-sign)', function(obj){
			var mid = this.value;
			var v = obj.elem.checked == true ? 1 : 0;
			caigouIsSign[mid] = v;
		});
	
		// 单元格修改数据校验
		window.checkData = function(d) {
			var caigouUnitprice = d.caigou_unitprice;
        	var billingCaigouCount = d.billing_caigou_count;
        	var caigouSubtotalMoney = d.caigou_subtotal_money;
        	var trueFabricWidth = d.true_fabric_width;
        	var trueWeight = d.true_weight;
        	
            var mid=d.mid;
            var stallId = d.stall_id;
            var stallOrderTime=$("#stall_order_time"+mid).val();
            
        	var reg = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/; // 正浮点数
        	var reg2 = /^([-+])?\d+(\.[0-9]{1,2})?$/; // 正负浮点数
        	if (!reg.test(caigouUnitprice)) {
        		layer.msg('采购物料单价填写有误', {icon: 2,anim: 6});
        		return false;
        	}
        	if (!reg2.test(billingCaigouCount)) {
        		layer.msg('开单采购数量填写有误', {icon: 2,anim: 6});
        		return false;
        	}
        	if (!reg.test(trueFabricWidth)) {
        		layer.msg('实际幅宽填写有误', {icon: 2,anim: 6});
        		return false;
        	}
        	if (!reg.test(trueWeight)) {
        		layer.msg('实际克重填写有误', {icon: 2,anim: 6});
        		return false;
        	}
            
            if (stallOrderTime=="") {
        		layer.msg('供应商日期不能为空', {icon: 2,anim: 6});
        		return false;
        	}
        	return true;
		}
		
		// 补料
		window.feedEvent = function(number, mid, obj) {
			var regInt = /^(\+|\-)?\d+$/;
			if(regInt.test(number)) {
				$.ajax({
			 		   type: "POST",
			 		   url: "{:url('costFeed')}",
			 		   data: "mid="+mid+"&number="+number,
			 		   dataType:"json",
			 		   success: function(res){
			 			  if (res.code == 1) {
			 				 var ori = $('.feed-detail-'+mid).html();
			 				 var newFeed = ori=='' ? number : (ori+(number>0?"+"+Math.abs(number):number));
			 				 $('.feed-detail-'+mid).html(newFeed);
			 				 obj.update({billing_caigou_count:res.data.billing_caigou_count,caigou_subtotal_money:res.data.caigou_subtotal_money});
			 				 $('.caigou-total-money-'+res.data.order_id).html(res.data.caigou_total_money);
							 layer.msg(res.msg, {icon: 1});
							 layer.closeAll();
						  } else {
							 layer.msg(res.msg, {icon: 2,anim: 6});
						  }
			 		   }
			 		});
			} else layer.msg('数量填写有误', {icon: 2,anim: 6});
		};
		
		/**
	     * layui非静态table搜索渲染
	     * @attr data-table table容器ID
	     * @attr hisi-data table基础参数
	     * @attr action 搜索请求地址
	     */
	   $(document).on('submit', '#hisiSearchOpTable,#hisi-table-search-optable', function() {
	        var that = $(this), 
	            arr = that.serializeArray(), 
	            where = new Array(),
	            dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
	            options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:1}};
	        
	            for(var i in arr) {
	                where[arr[i].name] = arr[i].value;
	            }
	        
	        options.url = that.attr('action');
	        options.where = where;
	        
	        opTable.reload(options);
	        return false;
	    });
		
		// 刷新当前页
		window.reloadTable = function () {
			var that = $("#hisi-table-search-optable"), 
	            arr = that.serializeArray(), 
	            where = new Array(),
	            dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
	            currPage = $(".layui-laypage-em").next().html(),
	            options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
           for(var i in arr) {
               where[arr[i].name] = arr[i].value;
           }
       
	        options.url = that.attr('action');
	        options.where = where;
	        
	        opTable.reload(options);
	        return false;
		}
	});
</script>